package com.oocl.controller;

import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.oocl.pojo.Customer;
import com.oocl.service.CustomerManager;
import com.oocl.service.factory.CustomerManagerFactory;

@Controller
@RequestMapping("/")
public class CustomerController {
	private CustomerManager manager;
	
	public CustomerController() {
		manager = CustomerManagerFactory.getInstance();
	}
	
	@RequestMapping(value="addCustomer",method=RequestMethod.POST)
	public String addCustomer(Customer customer){
		System.out.println(customer);
		manager.addCustomer(customer);
		return "redirect:findAll";
	}
	
	@RequestMapping("findAll")
	public String findAll(Model model){
		List<Customer> customers = manager.findAll();
		model.addAttribute("customers", customers);
		return "show";
	}
}
